package com.zy.chat.controller;

import com.zy.chat.entity.Dynamic;
import com.zy.chat.entity.ScrollResult;
import com.zy.chat.service.DynamicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zy
 * @date 2023/5/17 17:16
 */

@Controller
@RequestMapping(value = "dynamiccontroller")
public class DynamicController {

    @Autowired
    private DynamicService dynamicService;
    @PostMapping(value = "/insert")
    public ResponseEntity<Integer> insert(@RequestBody Dynamic dynamic){
      return new ResponseEntity<Integer>(dynamicService.insert(dynamic), HttpStatus.OK);
    }


    @GetMapping(value = "queryAll")
    public ResponseEntity<List<Dynamic>> queryAll(){
        return  new ResponseEntity<List<Dynamic>>(dynamicService.queryAll(),HttpStatus.OK);
    }

    @GetMapping(value = "/like/{id}")
    public ResponseEntity<Boolean> like(@PathVariable("id")long id){
        return new ResponseEntity<Boolean>(dynamicService.like(id),HttpStatus.OK);
    }

    @GetMapping(value = "/scroll/follow")
    public ResponseEntity<ScrollResult> scroll(@RequestParam(value = "max") long max,@RequestParam(value ="offset",defaultValue ="0")  Integer offset){
        return new ResponseEntity<ScrollResult>(dynamicService.scroll(max,offset),HttpStatus.OK);
    }
}
